#! /bin/sh

mkdir -p out || exit 99

name=$( basename "$0" )
datafile="$srcdir/${name}.data"
dumpfile="out/${name}.dump"
resultfile="out/${name}.result"
expectfile="$srcdir/${name}.expect"

./mkelf "$dumpfile" <<EOF
ei_class = 2
ei_data = 1
e_machine = 183
e_phoff = 0x1000

DATA = $datafile
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Cannot create ELF file" >&2
    exit $rc
fi
echo "Created ELF dump: $dumpfile"

./checkattr "$dumpfile" <<EOF
file = directory:
file.set.number = number:1
file.set.0 = directory:
file.set.0.fd = number
file.format = string: elf

cpu = directory:
cpu.number = number:1
cpu.0 = directory:
cpu.0.PRSTATUS = blob:\
0300000004000000050000000b000000\
70725f736967706570725f736967686f\
5f70696470706964706772705f736964\
000000000000000070725f7574696d65\
000000000000000070725f7374696d65\
000000000000000070725f637574696d\
000000000000000070725f637374696d\
20202020202078302020202020207831\
20202020202078322020202020207833\
20202020202078342020202020207835\
20202020202078362020202020207837\
20202020202078382020202020207839\
20202020207831302020202020783131\
20202020207831322020202020783133\
20202020207831342020202020783135\
20202020207831362020202020783137\
20202020207831382020202020783139\
20202020207832302020202020783231\
20202020207832322020202020783233\
20202020207832342020202020783235\
20202020207832362020202020783237\
20202020207832382020202020783239\
2020202020206c722020202020207370\
20202020202070632020707374617465\
0000000000000000
cpu.0.reg = directory:
cpu.0.reg.x0  = number:0x3078202020202020
cpu.0.reg.x1  = number:0x3178202020202020
cpu.0.reg.x2  = number:0x3278202020202020
cpu.0.reg.x3  = number:0x3378202020202020
cpu.0.reg.x4  = number:0x3478202020202020
cpu.0.reg.x5  = number:0x3578202020202020
cpu.0.reg.x6  = number:0x3678202020202020
cpu.0.reg.x7  = number:0x3778202020202020
cpu.0.reg.x8  = number:0x3878202020202020
cpu.0.reg.x9  = number:0x3978202020202020
cpu.0.reg.x10 = number:0x3031782020202020
cpu.0.reg.x11 = number:0x3131782020202020
cpu.0.reg.x12 = number:0x3231782020202020
cpu.0.reg.x13 = number:0x3331782020202020
cpu.0.reg.x14 = number:0x3431782020202020
cpu.0.reg.x15 = number:0x3531782020202020
cpu.0.reg.x16 = number:0x3631782020202020
cpu.0.reg.x17 = number:0x3731782020202020
cpu.0.reg.x18 = number:0x3831782020202020
cpu.0.reg.x19 = number:0x3931782020202020
cpu.0.pid = number:0x6469705f
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Attribute check failed" >&2
    exit $rc
fi

exit 0
